package org.edu.modules.classChoise.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.edu.modules.classChoise.entity.*;

import org.edu.modules.classChoise.mapper.VeJwSxjxMapper;
import org.edu.modules.classChoise.mapper.VeJwSxjxsecMapper;
import org.edu.modules.classChoise.mapper.VeJwSxjxstuMapper;
import org.edu.modules.classChoise.mapper.VeJwXkdjMapper;
import org.edu.modules.classChoise.service.IVeJwSxjxstuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Description: 选课时间
 * @Author:
 * @Date:   2021-05-14
 * @Version: V1.0
 */
@Service
public class VeJwSxjxstuServiceImpl extends ServiceImpl<VeJwSxjxstuMapper, VeJwSxjxstu> implements IVeJwSxjxstuService {

    @Autowired
    private VeJwSxjxstuMapper veJwSxjxstuMapper;


    @Override
    @Transactional
    public boolean setSxjxForStu(String[] xkdjids,String[] stuids,String sxjxid) {

      /*  veJwSxjxsecMapper.deleteAll(sxjxId);
        for (int i=0;i<sections.length;i++) {
            //veJwBpksj.setId(null);
            VeJwSxjxsec veJwSxjxsec=new VeJwSxjxsec();
            veJwSxjxsec.setSection(Integer.parseInt(sections[i]));
            veJwSxjxsec.setSxjxId(sxjxId);
            veJwSxjxsecMapper.insert(veJwSxjxsec);
        }*/

       try {
            //veJwSxjxstuMapper.deleteAll(stuid);
            for (int i=0;i<stuids.length;i++) {
                VeJwSxjxstu veJwSxjxstu = new VeJwSxjxstu();
                veJwSxjxstu.setStuid(Integer.parseInt(stuids[i]));
                veJwSxjxstu.setXkdjid(Integer.parseInt(xkdjids[i]));
              //  veJwSxjxstu.setXh(xhs[i]);
              //  veJwSxjxstu.setStuName(stunames[i]);
                veJwSxjxstu.setSxjxid(Integer.parseInt(sxjxid));
                //veJwBpksj.setId(null);
                veJwSxjxstuMapper.insert(veJwSxjxstu);
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }


    @Override
    @Transactional
    public boolean setNoSxjxForStu(String[] xkdjId,String[] stuids,String sxjxid) {
        try {
            for (int i=0;i<stuids.length;i++) {
                veJwSxjxstuMapper.deleteStubySxjx(xkdjId[i],stuids[i],sxjxid);
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }

  }
